home *** CD-ROM | disk | FTP | other *** search
/ Basic Instinct 2 Press Kit / Basic Instinct 2 Press Kit.iso / pc / main.dxr / FlashPaper_1_BIProdNotes.swf / scripts / __Packages / FPUI / NButton.as < prev    next >
Encoding:
Text File  |  2006-03-15  |  3.2 KB  |  152 lines

  1. class FPUI.NButton extends FPUI.Component
  2. {
  3.    var m_iconMC;
  4.    var m_active = false;
  5.    var m_keyHandler = null;
  6.    var m_state = "up";
  7.    var m_iconName = "";
  8.    var m_clickHandler = "";
  9.    var m_localName = "";
  10.    function NButton()
  11.    {
  12.       var _loc1_ = this;
  13.       super();
  14.       _loc1_.stop();
  15.       _loc1_.useHandCursor = false;
  16.       if(_loc1_.m_iconName != "")
  17.       {
  18.          var _loc2_ = _loc1_.attachMovie(_loc1_.m_iconName,"m_iconMC",99);
  19.          _loc2_._x = Math.round((_loc1_._width - _loc2_._width) / 2);
  20.          _loc2_._y = Math.round((_loc1_._height - _loc2_._height) / 2);
  21.          _loc2_.tabEnabled = false;
  22.       }
  23.       if(_loc1_._accImpl != null)
  24.       {
  25.          delete _loc1_._accImpl;
  26.          _loc1_._accImpl = null;
  27.       }
  28.    }
  29.    function onComponentSetFocus()
  30.    {
  31.       super.onComponentSetFocus();
  32.       this.go("focus");
  33.    }
  34.    function onComponentKillFocus()
  35.    {
  36.       super.onComponentKillFocus();
  37.       this.go("up");
  38.    }
  39.    function go(s)
  40.    {
  41.       var _loc1_ = s;
  42.       var _loc2_ = this;
  43.       _loc2_.m_state = _loc1_;
  44.       if(!_loc2_.m_enable)
  45.       {
  46.          _loc1_ = "up";
  47.       }
  48.       else if(_loc1_ == "up")
  49.       {
  50.          if(_loc2_.m_active)
  51.          {
  52.             _loc1_ = "over";
  53.          }
  54.          else if(_loc2_.getFocused())
  55.          {
  56.             _loc1_ = "focus";
  57.          }
  58.       }
  59.       else if(_loc1_ == "focus" && _loc2_.m_active)
  60.       {
  61.          _loc1_ = "over";
  62.       }
  63.       _loc2_.gotoAndStop(_loc1_);
  64.    }
  65.    function setEnabled(enabledFlag)
  66.    {
  67.       super.setEnabled(enabledFlag);
  68.       this.m_iconMC._alpha = !this.m_enable ? 50 : 100;
  69.    }
  70.    function setActive(a)
  71.    {
  72.       var _loc1_ = this;
  73.       _loc1_.m_active = a;
  74.       _loc1_.go(_loc1_.m_state);
  75.    }
  76.    function isActive()
  77.    {
  78.       return this.m_active;
  79.    }
  80.    function findListener(method)
  81.    {
  82.       var _loc2_ = method;
  83.       var _loc1_ = this._parent;
  84.       while(_loc1_ != null)
  85.       {
  86.          if(_loc1_.controller != undefined && _loc1_.controller[_loc2_] != undefined)
  87.          {
  88.             return _loc1_.controller;
  89.          }
  90.          _loc1_ = _loc1_._parent;
  91.       }
  92.       return null;
  93.    }
  94.    function sendListener(method)
  95.    {
  96.       var _loc1_ = this.findListener(method);
  97.       if(_loc1_ != null)
  98.       {
  99.          _loc1_[method]();
  100.       }
  101.    }
  102.    function setKeyHandler(h)
  103.    {
  104.       this.m_keyHandler = h;
  105.    }
  106.    function onComponentKeyDown()
  107.    {
  108.       var _loc1_ = this;
  109.       if(_loc1_.m_keyHandler)
  110.       {
  111.          _loc1_.m_keyHandler.onKeyDown();
  112.       }
  113.       else if(Key.getCode() == 13)
  114.       {
  115.          _loc1_.sendListener(_loc1_.m_clickHandler);
  116.       }
  117.    }
  118.    function onDragOver()
  119.    {
  120.       this.go("down");
  121.    }
  122.    function onDragOut()
  123.    {
  124.       this.go("up");
  125.    }
  126.    function onRollOver()
  127.    {
  128.       this.go("over");
  129.    }
  130.    function onRollOut()
  131.    {
  132.       this.go("up");
  133.    }
  134.    function onPress()
  135.    {
  136.       this.go("down");
  137.    }
  138.    function onRelease()
  139.    {
  140.       var _loc1_ = this;
  141.       if(_loc1_.m_enable)
  142.       {
  143.          _loc1_.sendListener(_loc1_.m_clickHandler);
  144.       }
  145.       _loc1_.go("over");
  146.    }
  147.    function onReleaseOutside()
  148.    {
  149.       this.go("up");
  150.    }
  151. }
  152.